#include "stdafx.h"
#include "resource.h"
#include "DBWorld.h"

DBWorld sDBWorld;
LRESULT CALLBACK DialogProc(HWND ,UINT,WPARAM,LPARAM);
int WINAPI WinMain(	HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR	lpCmdLine,int nCmdShow)
{		
	HWND hwnd = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_DB_SERVER), NULL, (DLGPROC)DialogProc);
	ShowWindow(hwnd, SW_SHOW);      
	UpdateWindow(hwnd);
	MSG msg;
	while(GetMessage(&msg, NULL, 0, 0))         
	{   
		if(!IsDialogMessage(hwnd, &msg))  
		{  
			TranslateMessage(&msg);  
			DispatchMessage(&msg);    
		} 
	}
	return	0;
}
LRESULT CALLBACK DialogProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)         
{    
	switch(uMsg)      
	{      
	case WM_INITDIALOG:
		sDBWorld.Init(GetDlgItem(hWnd, IDC_EDIT));
		return TRUE;
	case WM_COMMAND:
		if(LOWORD(wParam) == IDCANCEL)       
		{                     
			DestroyWindow(hWnd);                
			return TRUE;      
		}                 
		break;
	case WM_DESTROY:
		sDBWorld.Stop();
		PostQuitMessage(0);      
		break;  
	}      
	return FALSE;  
}